#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 25;
const int INF = 1e9;

int n, m;
int a[N];
int mns[N], mnv[N];
int ans = INF;
void dfs(int i, int mxr, int mxh, int v, int s) {
  if (i == 0) {
    if (v == n) ans = min(ans, s);
    return;
  }
  if (v + mnv[i] > n) return;
  if (s + mns[i] >= ans) return;
  int r1 = i, r2 = min(mxr, (int)sqrt((n - v) / i));
  per(r, r2, r1) {
    int s1 = 2 * (n - v) / r;
    if (s + s1 >= ans) break;
    int h1 = i, h2 = min(mxh, (n - v) / (r * r));
    per(h, h2, h1) {
      dfs(i - 1, r - 1, h - 1, v + r * r * h,
          s + 2 * r * h + (i == m ? r * r : 0));
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    mns[i] = mns[i - 1] + 2 * i * i;
    mnv[i] = mnv[i - 1] + i * i * i;
  }
  dfs(m, INF, INF, 0, 0);
  if (ans == INF) ans = 0;
  cout << ans;
  return 0;
}